<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <title>登陆</title>
    <link rel="stylesheet" href="css/reset.css">
    <link rel="stylesheet" href="css/jiazai.css">
    <style>
        .logo {
            padding: 80px 0 50px;
            text-align: center;
            font-size: 18px;
            color: white;
        }
        
        .logo>h1 {
            padding-top: 10px;
        }
        
        .input-wrap {
            padding: 20px;
            box-sizing: border-box;
        }
        
        .input-wrap>input {
            width: 100%;
            box-sizing: border-box;
            padding: 15px 10px;
            margin-top: 15px;
            font-size: 16px;
            color: white;
            background: #353742;
            border-radius: 5px;
        }
        
        .input-wrap>p:first-of-type {
            padding-top: 15px;
            color: #F25B5B;
            opacity: .7;
        }
        
        .input-wrap>p:last-of-type {
            margin-top: 25px;
            padding: 18px;
            text-align: center;
            font-size: 16px;
            color: white;
            background: #2590FE;
            opacity: .7;
            border-radius: 5px;
        }
        
        .input-wrap>h6 {
            padding-top: 10px;
            text-align: right;
            color: #2590FE;
        }
        
        .fixed-bottom {
            position: fixed;
            bottom: 40px;
            left: 0;
            right: 0;
            font-size: 14px;
            color: #2590FE;
            text-align: center;
            opacity: .8;
        }
        
    </style>
</head>

<body style="background:#2a2c35;">
    <div id='app'>

        <!-- 加载中动画 -->
        <div id='jiazai-ani' v-if='jiazai'>
            <div class="arc"></div>
            <h1><span>LOADING</span></h1>
        </div>
        <!-- 加载中动画 -->

        <div class='logo'>
            <div>
                <img src="./img/logo.png" width="100px" height="100px">
            </div>
            <h1 @click="console.log(plus.webview.all().length)">Coindapp</h1>
        </div>

        <div class='input-wrap'>
            <input type="text" placeholder="输入用户名" v-model='nickname'>
            <input type="password" placeholder="输入密码" v-model='password'>
            <p class='dis-spa'>
                <span v-text='notice'>提示：输入密码有误</span>
                <span style="color:white" @click="forgetPas">忘记密码？</span>
            </p>
            <p @click='login'>登陆</p>
            <!--<h6>已有用户{{userCount}}人</h6>-->
        </div>

        <div class='fixed-bottom' id='fixed-bottom' @click="_openHref({url:'regist.html',id:'regist'})">
            新用户，注册账号
        </div>
    </div>
    <script src="js/comm.js"></script>
    <script src="js/vue.min.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="js/indexBack.js"></script>
    <script>
        var app = new Vue({
            el: '#app',
            data: {
                jiazai: false,
                //手机号
                phone: '',
                //用户名
                nickname: '',
                //密码
                password: '',
                //提示语
                notice: '',
                userCount: ''
            },
            created: function() {
                var This = this;
                _post(USER_COUNT, {

                }, function(data) {
                    This.userCount = data.back.num;
                });
            },
            mounted: function() {
                // H5 plus事件处理
                var This = this;
                function plusReady() {
                    // 获取所有Webview窗口
                    if (localStorage.getItem('cc_user')) {
                        This.jiazai = true;
                        var web = plus.webview.create('index.html', 'index', {
                            statusbar: {
                                background: '#2a2c35'
                            },
                        });
                        web.addEventListener("loaded", function() {
                            setTimeout(function() {
                                This.jiazai = false;
                                web.show('none');
                            }, 200);
                        }, false);
                        return;
                    }
                    var index = plus.webview.currentWebview();
                    var all = plus.webview.all();
                    var indexUrl = index.getURL();
                    setTimeout(function() {
                        for (var i = 0; i < all.length; i++) {
                            if (all[i].getURL() != indexUrl) {
                                all[i].hide();
                            }
                        }
                    }, 800);
                    setTimeout(function() {
                        for (var i = 0; i < all.length; i++) {
                            if (all[i].getURL() != indexUrl) {
                                all[i].close('none');
                            }
                        }
                    }, 1500);
                }
                if (window.plus) {
                    plusReady();
                } else {
                    document.addEventListener('plusready', plusReady, false);
                }

                setTimeout(function() {
                    //处理点击input的时候影响定位问题
                    var h = document.body.scrollHeight;
                    window.onresize = function() {
                        if (document.body.scrollHeight < h) {
                            $('#fixed-bottom').hide();
                        } else {
                            $('#fixed-bottom').show();
                        }
                    };
                    setTimeout(function() {
                        $('#fixed-bottom').show();
                    }, 100);
                }, 500);
            },
            methods: {
                //忘记密码
                forgetPas: function() {
                    var web = _openHref({
                        url: 'edit-password.html',
                        id: 'editPassword'
                    });
                    setTimeout(function() {
                        web.evalJS("forgetPass()");
                    }, 200);
                },
                //登陆
                login: function() {
                    if (!this.nickname) {
                        this.notice = '请输入账号';
                        return;
                    }
                    if (!this.password) {
                        this.notice = '请输入密码';
                        return;
                    }
                    this.jiazai = true;
                    var This = this;
                    _post(LOGIN, {
                        nickname: This.nickname,
                        password: This.password
                    }, function(data) {
                        This.jiazai = false;
                        if (data.status == 1) {
                            _toast(data.msg);
                            localStorage.setItem('cc_user', JSON.stringify(data.back));
                            _openHref({
                                url: 'index.html',
                                id: 'index',
                                close: true
                            });
                        } else {
                            This.notice = data.msg;
                        }
                    });
                }
            }
        });
    </script>
</body>

</html>